/*封装模块化文件　　新建的.js文件

特殊類型
           XINT			json.Number					整型
           XSTR			json.String					字符串	"XXX"
           XSTRS			json.Array<String>	字符串列表		["XXX","YYY",...]
           XOPT			json.String					枚举<值,显示文本;...>，单选，不可为空		"XXX"
           XOPTS			json.Array<String>	复杂枚举<值,显示文本;...>		["XXX","YYY",...]
           XTIME			json.String					UTC时间		"XXX"
           XBOOL			json.Bool						布尔<true,显示文本;false,显示文本>	true
           XCERT			json.Object					证书		{}
           XRAW			json.Object					原始数据	{}
           XQUOTER<>	json.Array<String>	引用<目标地址>	["XXX","YYY",...]

 */

var formatDesc = {
  /**
   * table列表表头数据获取
   * @param fields getdesc返回的数据
   * @param filter  筛选出要显示的列，用于同一个接口展示不同的列表的情况
   * @returns {Array}
   
  getHeaderList(fields, filter) {
    let tableHeadList = [];

    for (let i = 0; i < fields.length; i++) {

      let headerObj = {
        colDisabled: false,
        colHidden: false,
        colSearch: true,
        colSort: false,
        qekey: '',
        typeCollection: fields[i].type,
        columnComment: fields[i].show,
        columnName: fields[i].name
      };

      if (fields[i].type == 'XQUOTER') {
        headerObj.qekey = fields[i].qekey;

      }
      if (fields[i].type == 'XBOOL') {
        headerObj.show_false = fields[i].show_false;
        headerObj.show_true = fields[i].show_true;
      }
      if (fields[i].type == 'XOPT' || fields[i].type == 'XOPTS') {//单选

        if (fields[i].display_enum) {
          headerObj.display_enum = fields[i].display_enum
        }
      }

      if (!filter) {
        tableHeadList.push(headerObj);
      } else {
        filter.map(item => {
          if (headerObj.columnComment == item) {
            tableHeadList.push(headerObj);
          }
        })
      }

    }
    return tableHeadList;
  },
*/
  /**
   *
   * 获取表单信息
   * @param fields
   * @param filter
   * @returns {Array}
   *  examples:this.formColumns =  [{ property: 'name', title: '配置名:', type: 'text', required: true, placeholder: '请输入配置名' },
   *   { property: 'config_content', title: '配置内容:', type: 'mutliInput', required: true, placeholder: '配置内容', isLimit: 5, isDelete: false },
   *   { property: 'type', title: '类型:', type: 'select', required: true, disabled: false, placeholder: '请选择类型', multiple: false,
   *        options: [{ id: 'custom', name: 'custom' }, { id: 'service', name: 'service' }] },
   *  { property: 'checkbox_name', type: 'checkbox', required: true, isAllCheck: true, checkAll: false, isIndeterminate: true, options: [] } ];
 
   */
  get(fields, filter) {
    console.log(1630, fields, filter)
    let formColumns = [];
    for (let i = 0; i < fields.length; i++) {
      let formObj = {}
      if (fields[i].cloumnType) {
        formObj = {
          property: fields[i].columnName,        // property   表示存储表单某类型数据的key值
          title: fields[i].columnComment + ':',      // title   表示表单某类型对应的标题
          type: fields[i].type,             // type 表示表单对应的类型       //todo 做个映射
          required: fields[i].nvoid ? true : false,   // required Boolean 是否为必填
          placeholder: '请输入' + fields[i].columnComment,
          isLimit: fields[i].size / 2,
          figure:fields[i].figure,
          columTiles: fields[i].columTiles,
          pickdata: fields[i].pickdata,
          elColCount: fields[i].elColCount,
          Hiddens: fields[i].Hiddens,
          display_enum: fields[i].display_enum,
        };
        if (fields[i].type == 'XSTR') {
          formObj.type = "str";
          formObj.strType = fields[i].strType;
        }
        if (fields[i].type == 'XQUOTER') {  //formObj.options=[{ id: 'custom', name: 'custom' }, { id: 'service', name: 'service' }]
          formObj.type = "checkbox";
          if (fields[i].display_enum) {
            formObj.options = fields[i].display_enum;
            formObj.isAllCheck = fields[i].isAllCheck;
            formObj.isIndeterminate = fields[i].isIndeterminate;
          }
        }
        if (fields[i].type == 'XBOOL') {
          formObj.type = "radio";
          if (fields[i].display_enum) {
            formObj.options = fields[i].display_enum;
          }
          // formObj.options = [{value: true, show: fields[i].show_true}, {value: false, show: fields[i].show_false}];
        }
        if (fields[i].type == 'XOPT') {
          formObj.type = "select";
          formObj.filterable = fields[i].filterable
          if (fields[i].display_enum) {
            formObj.options = fields[i].display_enum;
          }
          // if (fields[i].qpath) {
          //   formObj.qpath = fields[i].qpath
          // }
          // formObj.multiple = false;
        }
        if (fields[i].type == 'XTIME') {
          formObj.type = 'time';
        }
        if (fields[i].type == 'XCASCADER') {
          formObj.type = "cascader";
          formObj.options = fields[i].display_enum
        }
        if (fields[i].type == 'XFILE') {
          formObj.type = "uploadtext";
        }
        if (!filter) {
          // console.log(formObj, filter, "1111")
          formColumns.push(formObj);
        } else {
          filter.map(item => {
            if (fields[i].columnComment == item) {
              formColumns.push(formObj);
            }
          })
        }
      }
      // console.log(formObj, filter, "33333")
    }
    return formColumns;
  }

}

export default formatDesc; //把这个方法暴露出去，方便外部引用
